/*
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 *
 * Copyright @2008 the original author or authors.
 */
package com.bluestone.report;

import java.beans.PropertyChangeEvent;
import java.util.ArrayList;

/**
 * ProjectReportBean records some informations for the Project.
 * @author <a href="mailto:ming7655@gmail.com">Aaron</a> 
 */
public class ProjectReportBean extends AbstractReportBean{
	/**
	 * 
	 */
	private static final long serialVersionUID = 4994143932889389186L;

	private String projectId;

	private String projectName;

	private String projectVersion;

	private String projectSpeedRate;

	private String projectRetryCount;

	private String browserType;
	
	private int projectTCFailureCount=0;
	
	private int projectTCCount=0;
	
	private ArrayList testCaseReportBeans = new ArrayList(); 

	public String getBrowserType() {
		return browserType;
	}

	public void setBrowserType(String browserType) {
		this.browserType = browserType;
	}

	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	public String getProjectName() {
		return projectName;
	}

	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}

	public String getProjectRetryCount() {
		return projectRetryCount;
	}

	public void setProjectRetryCount(String projectRetryCount) {
		this.projectRetryCount = projectRetryCount;
	}

	public String getProjectSpeedRate() {
		return projectSpeedRate;
	}

	public void setProjectSpeedRate(String projectSpeedRate) {
		this.projectSpeedRate = projectSpeedRate;
	}

	public String getProjectVersion() {
		return projectVersion;
	}

	public void setProjectVersion(String projectVersion) {
		this.projectVersion = projectVersion;
	}

	public void propertyChange(PropertyChangeEvent evt) {
		super.propertyChange(evt);		
	}

	public int getProjectTCFailureCount() {
		return projectTCFailureCount;
	}

	public void setProjectTCFailureCount(int testCaseReTtyCount) {
		this.projectTCFailureCount = testCaseReTtyCount;
	}

	public int getProjectTCCount() {
		if(this.projectTCCount>0){
			return projectTCCount;
		}
		ArrayList testSuites = this.getChildren();
		if(testSuites==null){
			return 0;
		}
		for(int i = 0;i<testSuites.size();i++){
			TestSuiteReportBean tsrb = (TestSuiteReportBean)testSuites.get(i);
			ArrayList testCases = tsrb.getChildren();
			this.projectTCCount = this.projectTCCount+testCases.size();
			this.testCaseReportBeans.addAll(testCases);
		}
		return projectTCCount;
	}	
	
	public TestCaseReportBean getTestCaseReportBean(int index){
		if(this.getProjectTCCount()>0){
			Object obj = testCaseReportBeans.get(index);
			if(TestCaseReportBean.class.isInstance(obj)){
				return (TestCaseReportBean)obj;
			}
		}
		return null;
	}

}
